/*
 *@Description: 查询的一些方法
 *@Author:  lupan
 *@Date: 2019-07-14 18:50:35
*/

const dbMethos = {
  /*
   *@Description: 
   *@params: table：表名  data：Array（object）  [{name: abc, value：123}]
   *@Author:  lupan
   *@return  true：存在 false：不存在
   *@Date: 2019-07-14 18:53:33
  */
 isExist: async(table, data) => {
  let sql = `SELECT COUNT(*) as total FROM ${table} WHERE `
  data.forEach((item, index) => {
    sql += `${item.name} ${item.type ? item.type : '='} '${item.value}'`
    if (index !== data.length - 1) {
      sql += ' AND '
    }
  })
  let is
  await $query(sql).then(res => {
    if (res.code) {
      const total = res.data[0].total
      total === 0 ? is = false : is = true
    }
  })
  return is
 }
}

module.exports = dbMethos